package com.blrs.service.enterprise.sharelog.impl;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;
import java.util.UUID;

import com.blrs.common.exception.ServiceException;
import com.blrs.common.utils.SecurityUtils;
import com.blrs.common.utils.StringUtils;
import com.blrs.domain.*;
import com.blrs.mapper.*;
import com.blrs.service.maintype.IMainTypeService;
import com.blrs.system.domain.SysUploadFile;
import com.blrs.system.mapper.SysUploadFileMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.blrs.service.enterprise.sharelog.IEnterpriseShareLogService;

/**
 * 客户资源共享日志Service业务层处理
 * 
 * @author wang.chao
 * @date 2024-04-18
 */
@Service
public class EnterpriseShareLogServiceImpl implements IEnterpriseShareLogService 
{
    @Autowired
    private EnterpriseShareLogMapper enterpriseShareLogMapper;
    @Autowired
    private EnterpriseInfoMapper enterpriseInfoMapper;
    @Autowired
    private EnterpriseShareLogDetailMapper enterpriseShareLogDetailMapper;
    @Autowired
    private IMainTypeService mainTypeService;
    @Autowired
    private EnterprisePersonInfoMapper enterprisePersonInfoMapper;
    @Autowired
    private HonorManagementMapper honorManagementMapper;
    @Autowired
    private SysUploadFileMapper sysUploadFileMapper;

    /**
     * 查询客户资源共享日志
     * 
     * @param id 客户资源共享日志主键
     * @return 客户资源共享日志
     */
    @Override
    public EnterpriseShareLog selectEnterpriseShareLogById(String id)
    {
        return enterpriseShareLogMapper.selectEnterpriseShareLogById(id);
    }

    /**
     * 查询客户资源共享日志列表
     * 
     * @param enterpriseShareLog 客户资源共享日志
     * @return 客户资源共享日志
     */
    @Override
    public List<EnterpriseShareLog> selectEnterpriseShareLogList(EnterpriseShareLog enterpriseShareLog)
    {
        enterpriseShareLog.setReceiveEnterpriseId(SecurityUtils.getOrgId().toString());
        enterpriseShareLog.setPushId(SecurityUtils.getUserId().toString());
        return enterpriseShareLogMapper.selectEnterpriseShareLogList(enterpriseShareLog);
    }

    /**
     * 新增客户资源共享日志
     * 1.共享的数据都作为新客户进行新增操作
     * 2.并把共享客户的荣誉资质和人员带过来
     * @param enterpriseShareLog 客户资源共享日志
     * @return 结果
     */
    @Override
    public int insertEnterpriseShareLog(EnterpriseShareLog enterpriseShareLog) throws NoSuchFieldException, IllegalAccessException {
        int count = 0;
        String belongTo ="";
        String belongToName ="";
        String[] enterpriseIds;
        String[] enterpriseNames;
        Long userId = SecurityUtils.getUserId();

        if (userId==2){//如果当前登录用户为见实力平台 则需要把belongTo改为当前选择接收的企业id 平台向企业共享时
            belongTo = enterpriseShareLog.getReceiveEnterpriseId();
            belongToName = enterpriseShareLog.getReceiveEnterpriseName();

        }else{//否则belongTo改为100 企业向平台共享时
            belongTo = "100";
            belongToName = "见实力工业企业云平台";
        }
        System.out.println(enterpriseShareLog.getShareEnterpriseId().length());

        boolean contains = enterpriseShareLog.getShareEnterpriseId().indexOf(",") >= 0;
        int failureNum = 0;
        int successNum = 0;
        StringBuilder successMsg = new StringBuilder();
        StringBuilder failureMsg = new StringBuilder();
        //判断是否选择了多个客户进行共享
        if(contains==true){//多选
            enterpriseIds = enterpriseShareLog.getShareEnterpriseId().split(",");
            enterpriseNames = enterpriseShareLog.getShareEnterpriseName().split(",");
            for (int i1 = 0; i1 < enterpriseIds.length; i1++) {
                try{
                    Long number = enterpriseInfoMapper.number(enterpriseNames[i1],belongTo);
                    if(number>0){
                        failureNum++;
                        failureMsg.append(failureNum +"、"+ enterpriseNames[i1]);
                    }
                }catch (Exception e) {
                    failureNum++;
                    String msg = "<br/>" + failureNum + "、数据共享失败：";
                    failureMsg.append(msg + e.getMessage());
                }

            }
            if(failureNum>0){
                failureMsg.insert(0, "很抱歉，共享失败！" + failureNum + " 条客户信息已存在，请勿重复共享：");
                throw new ServiceException(failureMsg.toString());
            }else{//输入所有重复企业名称
            //新增日志表
            EnterpriseShareLog enterpriseShareLogNew = new EnterpriseShareLog();
            enterpriseShareLogNew.setId(UUID.randomUUID().toString());
            enterpriseShareLogNew.setReceiveEnterpriseId(enterpriseShareLog.getReceiveEnterpriseId());//接收企业id
            enterpriseShareLogNew.setReceiveEnterpriseName(enterpriseShareLog.getReceiveEnterpriseName());//接收企业名称
            enterpriseShareLogNew.setPushId(SecurityUtils.getUserId().toString());
            enterpriseShareLogNew.setPushName(SecurityUtils.getUsername());
            enterpriseShareLogNew.setPushTime(new Timestamp(new Date().getTime()));
            enterpriseShareLogMapper.insertEnterpriseShareLog(enterpriseShareLogNew);
            for (int i = 0; i < enterpriseIds.length; i++) {
                EnterpriseShareLogDetail enterpriseShareLogDetail = new EnterpriseShareLogDetail();
                enterpriseShareLogDetail.setId(UUID.randomUUID().toString());
                enterpriseShareLogDetail.setLogId(enterpriseShareLogNew.getId());
                //共享的企业id
                enterpriseShareLogDetail.setShareEnterpriseId(enterpriseIds[i]);//共享的客户id
                enterpriseShareLogDetail.setShareEnterpriseName(enterpriseNames[i]);//共享的客户名称
                enterpriseShareLogDetail.setPushId(SecurityUtils.getUserId().toString());
                enterpriseShareLogDetail.setPushName(SecurityUtils.getUsername());
                enterpriseShareLogDetail.setPushTime(new Timestamp(new Date().getTime()));
                count = enterpriseShareLogDetailMapper.insertEnterpriseShareLogDetail(enterpriseShareLogDetail);

                //客户信息新增 多选
                EnterpriseInfo enterpriseInfoAdd = new EnterpriseInfo();
                //拿推送的客户id去查询客户信息 再进行新客户新增操作
                EnterpriseInfo enterpriseInfo = enterpriseInfoMapper.selectEnterpriseInfoByEnterpriseId(enterpriseIds[i]);
                String no = enterpriseInfoMapper.getMaxEnterpriseNo(enterpriseShareLog.getReceiveEnterpriseId());
                int noo;
                if (!StringUtils.isEmpty(no)) {
                    noo = Integer.parseInt(no) + 1;
                } else {
                    noo = 1;
                }
                enterpriseInfoAdd.setEnterpriseId(UUID.randomUUID().toString());
                enterpriseInfoAdd.setEnterpriseOrgId(enterpriseInfo.getEnterpriseOrgId());
                enterpriseInfoAdd.setEnterpriseName(enterpriseInfo.getEnterpriseName());
                enterpriseInfoAdd.setEnterpriseSource("14");
                enterpriseInfoAdd.setEnterpriseAbbreviation(enterpriseInfo.getEnterpriseAbbreviation());
                enterpriseInfoAdd.setAdministrativeArea(enterpriseInfo.getAdministrativeArea());
                enterpriseInfoAdd.setLegalRepresentative(enterpriseInfo.getLegalRepresentative());
                enterpriseInfoAdd.setEstablishmentDate(enterpriseInfo.getEstablishmentDate());
                enterpriseInfoAdd.setContractAmount(enterpriseInfo.getContractAmount());
                enterpriseInfoAdd.setEnterpriseLabel(enterpriseInfo.getEnterpriseLabel());
                enterpriseInfoAdd.setRegisteredCapital(enterpriseInfo.getRegisteredCapital());
                enterpriseInfoAdd.setIndustryType(enterpriseInfo.getIndustryType());
                enterpriseInfoAdd.setIndustry(enterpriseInfo.getIndustry());
                enterpriseInfoAdd.setContacts(enterpriseInfo.getContacts());
                enterpriseInfoAdd.setTelephone(enterpriseInfo.getTelephone());
                enterpriseInfoAdd.setBankName(enterpriseInfo.getBankName());
                enterpriseInfoAdd.setTaxId(enterpriseInfo.getTaxId());
                enterpriseInfoAdd.setEnterpriseAddress(enterpriseInfo.getEnterpriseAddress());
                enterpriseInfoAdd.setBusinessScope(enterpriseInfo.getBusinessScope());
                enterpriseInfoAdd.setEnterpriseNature(enterpriseInfo.getEnterpriseNature());
                enterpriseInfoAdd.setMarkAs("1");
                enterpriseInfoAdd.setEnterpriseNo(noo);
                enterpriseInfoAdd.setBankNo(enterpriseInfo.getBankNo());
                enterpriseInfoAdd.setClassificationName(enterpriseInfo.getClassificationName());
                enterpriseInfoAdd.setStatus(enterpriseInfo.getStatus());
                enterpriseInfoAdd.setCreationId(enterpriseInfo.getCreationId());
                enterpriseInfoAdd.setCreationName(enterpriseInfo.getCreationName());
                enterpriseInfoAdd.setCreationTime(enterpriseInfo.getCreationTime());
                enterpriseInfoAdd.setOrganizationId(Long.valueOf(belongTo));
                enterpriseInfoAdd.setOrganizationName(belongToName);
                enterpriseInfoAdd.setDelFlag("0");
                enterpriseInfoAdd.setBelongTo(belongTo);
                enterpriseInfoAdd.setClassificationId("650c44e1-b575-4b62-9d54-1ba9d1e8abb7");

                //根据推送的企业id查询关联的人员信息
                EnterprisePersonInfo personInfoQuery = new EnterprisePersonInfo();
                personInfoQuery.setEnterpriseId(enterpriseIds[i]);
                List<EnterprisePersonInfo> personInfoList = enterprisePersonInfoMapper.selectEnterprisePersonInfoListByPhone(personInfoQuery);
                if (personInfoList.size() > 0) {
                    for (int k = 0; k < personInfoList.size(); k++) {
                        EnterprisePersonInfo personInfo = new EnterprisePersonInfo();
                        personInfo.setId(UUID.randomUUID().toString());
                        personInfo.setPhone(personInfoList.get(k).getPhone());
                        personInfo.setName(personInfoList.get(k).getName());
                        //新的客户id
                        personInfo.setEnterpriseId(enterpriseInfoAdd.getEnterpriseId());
                        personInfo.setEnterpriseName(enterpriseInfoAdd.getEnterpriseName());
                        personInfo.setCreateId(personInfoList.get(k).getCreateId());
                        personInfo.setOrganizationId(Long.valueOf(belongTo));
                        personInfo.setOrganizationName(belongToName);
                        personInfo.setClassificationId("650c44e1-b575-4b62-9d54-1ba9d1e8abb7");
                        personInfo.setFilingTime(new Timestamp(new Date().getTime()));
                        personInfo.setCreationTime(new Timestamp(new Date().getTime()));
                        personInfo.setOperateTime(new Timestamp(new Date().getTime()));
                        personInfo.setDelFlag(0);
                        //新增人员信息
                        enterprisePersonInfoMapper.insertEnterprisePersonInfo(personInfo);
                    }
                }

                //根据推送的企业id查询关联的资质荣誉
                HonorManagement honorQuery = new HonorManagement();
                honorQuery.setEnterpriseName(enterpriseNames[i]);
                List<HonorManagement> honorList = honorManagementMapper.selectHonorManagementList(honorQuery);
                if (honorList.size() > 0) {
                    for (int j = 0; j < honorList.size(); j++) {
                        HonorManagement management = new HonorManagement();
                        management.setId(UUID.randomUUID().toString());
                        management.setCustomerId(enterpriseInfoAdd.getEnterpriseId());
                        management.setEnterpriseName(enterpriseInfoAdd.getEnterpriseName());
                        management.setType(honorList.get(j).getType());
                        management.setLevel(honorList.get(j).getLevel());
                        management.setProjectId(honorList.get(j).getProjectId());
                        management.setServiceInstitu(honorList.get(j).getServiceInstitu());
                        management.setCertificateInstitution(honorList.get(j).getCertificateInstitution());
                        management.setIssuanceTime(honorList.get(j).getIssuanceTime());
                        management.setEffectiveTime(honorList.get(j).getName());
                        management.setAbutmentTime(honorList.get(j).getAbutmentTime());
                        management.setSelectUrl(honorList.get(j).getSelectUrl());
                        management.setStatus(honorList.get(j).getStatus());
                        management.setClassificationId(honorList.get(j).getClassificationId());
                        management.setEntryTime(honorList.get(j).getEntryTime());
                        management.setUploadFile(management.getId());
                        management.setCreateId(honorList.get(j).getCreateId());
                        management.setCreateBy(honorList.get(j).getCreateBy());
                        management.setCreationTime(new Timestamp(new Date().getTime()));
                        management.setOrganizationId(Long.valueOf(belongTo));
                        management.setOrganizationName(belongToName);
                        management.setClassificationId("650c44e1-b575-4b62-9d54-1ba9d1e8abb7");

                        SysUploadFile uploadFile = new SysUploadFile();
                        uploadFile.setBusinessId(honorList.get(j).getUploadFile());
                        List<SysUploadFile> uploadFileList = sysUploadFileMapper.selectSysUploadFileList(uploadFile);
                        //获取荣誉资质附件
                        if (uploadFileList.size() > 0) {
                            SysUploadFile uploadFileAdd = new SysUploadFile();
                            uploadFileAdd.setId(UUID.randomUUID().toString());
                            uploadFileAdd.setBusinessId(management.getId());
                            uploadFileAdd.setBusinessCode("honor");
                            uploadFileAdd.setFileName(uploadFileList.get(0).getNewFileName());
                            uploadFileAdd.setFileType(uploadFileList.get(0).getFileType());
                            uploadFileAdd.setFileSize(uploadFileList.get(0).getFileSize());
                            uploadFileAdd.setUrl(uploadFileList.get(0).getUrl());
                            uploadFileAdd.setPhyPath(uploadFileList.get(0).getPhyPath());
                            uploadFileAdd.setContent(uploadFileList.get(0).getContent());
                            uploadFileAdd.setCreateBy(uploadFileList.get(0).getCreateBy());
                            uploadFileAdd.setCreationTime(new Timestamp(new Date().getTime()));
                            uploadFileAdd.setOrganizationId(Long.valueOf(belongTo));
                            uploadFileAdd.setOrganizationName(belongToName);
                            sysUploadFileMapper.insertSysUploadFile(uploadFileAdd);
                        }
                        //新增荣誉资质信息
                            honorManagementMapper.insertHonorManagement(management);
                        }
                    }

                    //修改旧数据为已共享
                    enterpriseInfo.setIsShare("1");
                    enterpriseInfoMapper.updateEnterpriseInfo(enterpriseInfo);
                    //新接受的共享数据为 未共享
                    enterpriseInfoAdd.setIsShare("0");
                    enterpriseInfoMapper.insertEnterpriseInfo(enterpriseInfoAdd);
                }
            }
        }else{
            ///////////////////////////////////////////////单选
            try{
                Long number = enterpriseInfoMapper.number(enterpriseShareLog.getShareEnterpriseName(),belongTo);
                if(number>0){
                    failureNum++;
                    failureMsg.append(failureNum +"、"+ enterpriseShareLog.getShareEnterpriseName());
                }
            }catch (Exception e) {
                failureNum++;
                String msg = "<br/>" + failureNum + "、数据共享失败：";
                failureMsg.append(msg + e.getMessage());
            }
            if(failureNum>0){
                failureMsg.insert(0, "很抱歉，共享失败！" + failureNum + " 条客户信息已存在，请勿重复共享：");
                throw new ServiceException(failureMsg.toString());
            }else{
                //新增日志表
                EnterpriseShareLog enterpriseShareLogNew = new EnterpriseShareLog();
                enterpriseShareLogNew.setId(UUID.randomUUID().toString());
                enterpriseShareLogNew.setReceiveEnterpriseId(enterpriseShareLog.getReceiveEnterpriseId());//接收企业id
                enterpriseShareLogNew.setReceiveEnterpriseName(enterpriseShareLog.getReceiveEnterpriseName());//接收企业名称
                enterpriseShareLogNew.setPushId(SecurityUtils.getUserId().toString());
                enterpriseShareLogNew.setPushName(SecurityUtils.getUsername());
                enterpriseShareLogNew.setPushTime(new Timestamp(new Date().getTime()));
                enterpriseShareLogMapper.insertEnterpriseShareLog(enterpriseShareLogNew);
                EnterpriseShareLogDetail enterpriseShareLogDetail = new EnterpriseShareLogDetail();
                enterpriseShareLogDetail.setId(UUID.randomUUID().toString());
                enterpriseShareLogDetail.setLogId(enterpriseShareLogNew.getId());
                //共享的企业id
                enterpriseShareLogDetail.setShareEnterpriseId(enterpriseShareLog.getShareEnterpriseId());
                enterpriseShareLogDetail.setShareEnterpriseName(enterpriseShareLog.getShareEnterpriseName());
                enterpriseShareLogDetail.setPushId(SecurityUtils.getUserId().toString());
                enterpriseShareLogDetail.setPushName(SecurityUtils.getUsername());
                enterpriseShareLogDetail.setPushTime(new Timestamp(new Date().getTime()));
                count = enterpriseShareLogDetailMapper.insertEnterpriseShareLogDetail(enterpriseShareLogDetail);

                //客户信息新增
                EnterpriseInfo enterpriseInfoAdd = new EnterpriseInfo();
                //拿推送的客户id去查询客户信息 再进行新客户新增操作
                EnterpriseInfo enterpriseInfo = enterpriseInfoMapper.selectEnterpriseInfoByEnterpriseId(enterpriseShareLog.getShareEnterpriseId());
                enterpriseInfoAdd.setEnterpriseId(UUID.randomUUID().toString());
                enterpriseInfoAdd.setEnterpriseOrgId(enterpriseInfo.getEnterpriseOrgId());
                enterpriseInfoAdd.setEnterpriseName(enterpriseInfo.getEnterpriseName());
                enterpriseInfoAdd.setEnterpriseSource("14");
                enterpriseInfoAdd.setMarkAs("1");
                enterpriseInfoAdd.setEnterpriseAbbreviation(enterpriseInfo.getEnterpriseAbbreviation());
                enterpriseInfoAdd.setAdministrativeArea(enterpriseInfo.getAdministrativeArea());
                enterpriseInfoAdd.setLegalRepresentative(enterpriseInfo.getLegalRepresentative());
                enterpriseInfoAdd.setEstablishmentDate(enterpriseInfo.getEstablishmentDate());
                enterpriseInfoAdd.setContractAmount(enterpriseInfo.getContractAmount());
                enterpriseInfoAdd.setEnterpriseLabel(enterpriseInfo.getEnterpriseLabel());
                enterpriseInfoAdd.setRegisteredCapital(enterpriseInfo.getRegisteredCapital());
                enterpriseInfoAdd.setIndustryType(enterpriseInfo.getIndustryType());
                enterpriseInfoAdd.setIndustry(enterpriseInfo.getIndustry());
                enterpriseInfoAdd.setContacts(enterpriseInfo.getContacts());
                enterpriseInfoAdd.setTelephone(enterpriseInfo.getTelephone());
                enterpriseInfoAdd.setBankName(enterpriseInfo.getBankName());
                enterpriseInfoAdd.setTaxId(enterpriseInfo.getTaxId());
                enterpriseInfoAdd.setEnterpriseAddress(enterpriseInfo.getEnterpriseAddress());
                enterpriseInfoAdd.setBusinessScope(enterpriseInfo.getBusinessScope());
                enterpriseInfoAdd.setEnterpriseNature(enterpriseInfo.getEnterpriseNature());
                String no = enterpriseInfoMapper.getMaxEnterpriseNo(enterpriseShareLog.getReceiveEnterpriseId());
                int noo;
                if(!StringUtils.isEmpty(no)){
                    noo = Integer.parseInt(no) + 1;
                }else{
                    noo = 1;
                }
                enterpriseInfoAdd.setEnterpriseNo(noo);
                enterpriseInfoAdd.setBankNo(enterpriseInfo.getBankNo());
                enterpriseInfoAdd.setClassificationName(enterpriseInfo.getClassificationName());
                enterpriseInfoAdd.setStatus(enterpriseInfo.getStatus());
                enterpriseInfoAdd.setCreationId(enterpriseInfo.getCreationId());
                enterpriseInfoAdd.setCreationName(enterpriseInfo.getCreationName());
                enterpriseInfoAdd.setCreationTime(enterpriseInfo.getCreationTime());
                enterpriseInfoAdd.setOrganizationId(Long.valueOf(belongTo));
                enterpriseInfoAdd.setOrganizationName(belongToName);
                enterpriseInfoAdd.setDelFlag("0");
                enterpriseInfoAdd.setBelongTo(belongTo);
                enterpriseInfoAdd.setClassificationId("650c44e1-b575-4b62-9d54-1ba9d1e8abb7");


                //根据推送的企业id查询关联的人员信息
                EnterprisePersonInfo personInfoQuery = new EnterprisePersonInfo();
                personInfoQuery.setEnterpriseId(enterpriseShareLog.getShareEnterpriseId());
                List<EnterprisePersonInfo> personInfoList = enterprisePersonInfoMapper.selectEnterprisePersonInfoListByPhone(personInfoQuery);
                if (personInfoList.size() > 0) {
                    for(int i=0;i<personInfoList.size();i++){
                        EnterprisePersonInfo personInfo = new EnterprisePersonInfo();
                        personInfo.setId(UUID.randomUUID().toString());
                        personInfo.setPhone(personInfoList.get(i).getPhone());
                        personInfo.setName(personInfoList.get(i).getName());
                        //新的客户id
                        personInfo.setEnterpriseId(enterpriseInfoAdd.getEnterpriseId());
                        personInfo.setEnterpriseName(enterpriseInfoAdd.getEnterpriseName());
                        personInfo.setCreateId(SecurityUtils.getUserId());
                        personInfo.setOrganizationId(Long.valueOf(belongTo));
                        personInfo.setOrganizationName(belongToName);
                        personInfo.setClassificationId("650c44e1-b575-4b62-9d54-1ba9d1e8abb7");
                        personInfo.setFilingTime(new Timestamp(new Date().getTime()));
                        personInfo.setCreationTime(new Timestamp(new Date().getTime()));
                        personInfo.setOperateTime(new Timestamp(new Date().getTime()));
                        personInfo.setDelFlag(0);
                        //新增人员信息
                        enterprisePersonInfoMapper.insertEnterprisePersonInfo(personInfo);
                    }
                }

                //根据推送的企业id查询关联的资质荣誉
                HonorManagement honorQuery = new HonorManagement();
                honorQuery.setEnterpriseName(enterpriseShareLog.getShareEnterpriseName());
                List<HonorManagement> honorList = honorManagementMapper.selectHonorManagementList(honorQuery);
                if (honorList.size() > 0) {
                    for(int j=0;j<honorList.size();j++){
                        HonorManagement management = new HonorManagement();
                        management.setId(UUID.randomUUID().toString());
                        management.setCustomerId(enterpriseInfoAdd.getEnterpriseId());
                        management.setEnterpriseName(enterpriseInfoAdd.getEnterpriseName());
                        management.setType(honorList.get(j).getType());
                        management.setLevel(honorList.get(j).getLevel());
                        management.setProjectId(honorList.get(j).getProjectId());
                        management.setServiceInstitu(honorList.get(j).getServiceInstitu());
                        management.setCertificateInstitution(honorList.get(j).getCertificateInstitution());
                        management.setIssuanceTime(honorList.get(j).getIssuanceTime());
                        management.setEffectiveTime(honorList.get(j).getName());
                        management.setAbutmentTime(honorList.get(j).getAbutmentTime());
                        management.setSelectUrl(honorList.get(j).getSelectUrl());
                        management.setStatus(honorList.get(j).getStatus());
                        management.setClassificationId(honorList.get(j).getClassificationId());
                        management.setEntryTime(honorList.get(j).getEntryTime());
                        management.setUploadFile(management.getId());
                        management.setCreateId(honorList.get(j).getCreateId());
                        management.setCreateBy(honorList.get(j).getCreateBy());
                        management.setCreationTime(honorList.get(j).getCreationTime());
                        management.setOrganizationId(Long.valueOf(belongTo));
                        management.setOrganizationName(belongToName);
                        management.setClassificationId("650c44e1-b575-4b62-9d54-1ba9d1e8abb7");

                        SysUploadFile uploadFile = new SysUploadFile();
                        uploadFile.setBusinessId(honorList.get(j).getUploadFile());
                        List<SysUploadFile> uploadFileList = sysUploadFileMapper.selectSysUploadFileList(uploadFile);
                        //获取荣誉资质附件
                        if(uploadFileList.size()>0){
                            SysUploadFile uploadFileAdd = new SysUploadFile();
                            uploadFileAdd.setId(UUID.randomUUID().toString());
                            uploadFileAdd.setBusinessId(management.getId());
                            uploadFileAdd.setBusinessCode("honor");
                            uploadFileAdd.setFileName(uploadFileList.get(0).getNewFileName());
                            uploadFileAdd.setFileType(uploadFileList.get(0).getFileType());
                            uploadFileAdd.setFileSize(uploadFileList.get(0).getFileSize());
                            uploadFileAdd.setUrl(uploadFileList.get(0).getUrl());
                            uploadFileAdd.setPhyPath(uploadFileList.get(0).getPhyPath());
                            uploadFileAdd.setContent(uploadFileList.get(0).getContent());
                            uploadFileAdd.setCreateBy(uploadFileList.get(0).getCreateBy());
                            uploadFileAdd.setCreationTime(new Timestamp(new Date().getTime()));
                            uploadFileAdd.setOrganizationId(Long.valueOf(belongTo));
                            uploadFileAdd.setOrganizationName(belongToName);
                            sysUploadFileMapper.insertSysUploadFile(uploadFileAdd);
                        }
                        //新增荣誉资质信息
                        honorManagementMapper.insertHonorManagement(management);
                    }
                }
                //修改旧数据为已共享
                enterpriseInfo.setIsShare("1");
                enterpriseInfoMapper.updateEnterpriseInfo(enterpriseInfo);
                //新接受的共享数据为 未共享
                enterpriseInfoAdd.setIsShare("0");
                enterpriseInfoMapper.insertEnterpriseInfo(enterpriseInfoAdd);
            }
        }
        return count;
    }

    /**
     * 修改客户资源共享日志
     * 
     * @param enterpriseShareLog 客户资源共享日志
     * @return 结果
     */
    @Override
    public int updateEnterpriseShareLog(EnterpriseShareLog enterpriseShareLog)
    {
        return enterpriseShareLogMapper.updateEnterpriseShareLog(enterpriseShareLog);
    }

    /**
     * 批量删除客户资源共享日志
     * 
     * @param ids 需要删除的客户资源共享日志主键
     * @return 结果
     */
    @Override
    public int deleteEnterpriseShareLogByIds(String[] ids)
    {
        return enterpriseShareLogMapper.deleteEnterpriseShareLogByIds(ids);
    }

    /**
     * 删除客户资源共享日志信息
     * 
     * @param id 客户资源共享日志主键
     * @return 结果
     */
    @Override
    public int deleteEnterpriseShareLogById(String id)
    {
        return enterpriseShareLogMapper.deleteEnterpriseShareLogById(id);
    }
}
